package cn.sumpu.app.guoguojie.dao.impl;

import java.util.List;
import java.util.Map;

import org.mybatis.spring.support.SqlSessionDaoSupport;

import cn.sumpu.app.guoguojie.dao.TopShopDao;
import cn.sumpu.app.guoguojie.domain.TaobaokeShop;
import cn.sumpu.app.guoguojie.exception.AppBusinessException;

public class TopShopDaoImpl extends SqlSessionDaoSupport implements TopShopDao {

    @Override
    public void insertTopShop(TaobaokeShop taobaokeShop) throws AppBusinessException {
        try {
            getSqlSession().insert("cn.sumpu.app.guoguojie.persistence.TopShopMapper.insertTopShop", taobaokeShop);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("insertTopShop failure.", e);
            }
            throw new AppBusinessException("insertTopShop failure.", e);
        }
    }

    @Override
    public void updateTopShop(TaobaokeShop taobaokeShop) throws AppBusinessException {
        try {
            getSqlSession().update("cn.sumpu.app.guoguojie.persistence.TopShopMapper.updateTopShop", taobaokeShop);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("updateTopShop failure.", e);
            }
            throw new AppBusinessException("updateTopShop failure.", e);
        }
    }

    @Override
    public void deleteTopShop(Map<String, Object> map) throws AppBusinessException {
        try {
            getSqlSession().delete("cn.sumpu.app.guoguojie.persistence.TopShopMapper.deleteTopShop", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("deleteTopShop failure.", e);
            }
            throw new AppBusinessException("deleteTopShop failure.", e);
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<TaobaokeShop> getTopShop(Map<String, Object> map) throws AppBusinessException {
        try {
            return (List<TaobaokeShop>) getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.TopShopMapper.getTopShop", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getTopShop failure.", e);
            }
            throw new AppBusinessException("getTopShop failure.", e);
        }
    }

    @Override
    public int getTopShopCount(Map<String, Object> map) throws AppBusinessException {
        try {
            Object obj = getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.TopShopMapper.getTopShopCount", map);
            return (Integer) (obj == null ? 0 : obj);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getTopShopCount failure.", e);
            }
            throw new AppBusinessException("getTopShopCount failure.", e);
        }
    }

}
